<template>
  <div class="wrapper">
    <div class="header">
      <div class="header-item">
        <i class="el-icon-collection-tag"></i>我的收藏
      </div>
    </div>
    <div class="content">
      <!-- 没有数据 -->
      <div v-if="collectlist.length === 0" class="imgss">
        <img src="../assets/imgs/cart-empty.png" alt="" />
        <div class="right">
          <h2>您的收藏还是空的！</h2>
          <p>快去购物吧!</p>
        </div>
      </div>
      <div
        class="imgs-item"
        v-for="item in collectlist"
        :key="item.product_id"
        v-else
      >
        <div class="imgs-box">
          <el-popover placement="top" width="100">
            <p>您确定删除吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button
                type="primary"
                size="mini"
                @click="getdelCollect(item.product_id)"
                >确定</el-button
              >
            </div>
            <div class="span" slot="reference">×</div>
          </el-popover>
          <img
            :src="'http://101.132.181.9:3000/' + item.product_picture"
            alt=""
            @click="tiao(item.product_id)"
          />
        </div>

        <div class="imgs-zi">
          <h2>{{ item.product_name }}</h2>
          <h3>{{ item.product_title }}</h3>
          <p>
            <span>{{ item.product_selling_price }}元</span>
            <span
              class="del"
              v-show="item.product_price !== item.product_selling_price"
              >{{ item.product_price }}元</span
            >
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { CollectAll, delCollect } from "@/api/collects";
export default {
  name: "collect",
  data() {
    return {
      collectlist: [],
      userId: this.$store.state.users.user_id,
    };
  },
  created() {
    this.getCollectList();
  },
  methods: {
    /**
     * 跳转详情
     */
    tiao(type) {
      this.$router.push({
        path: "/goods/details", //跳转的路由
        query: {
          //跳转路由的参数
          type: type, //前面的type是参数的名称 //后面的type是点击产品时传过来的型号 这里也就是m320
        },
      });
    },
    /**
     * 删除收藏
     */
    async getdelCollect(pid) {
      const res = await delCollect({
        user_id: this.userId,
        product_id: pid,
      });
      console.log("删除", res);
      if (res.data.code == "001") {
        this.getCollectList();
        this.$notify.success({
          title: "成功",
          message: res.data.msg,
          showClose: true,
        });
      }
    },
    /**
     * 获取数据
     */
    async getCollectList() {
      const res = await CollectAll({
        user_id: this.userId,
      });
      console.log(res);
      if (res.data.code === "001") {
        this.collectlist = res.data.collectList;
        console.log(this.collectlist);
        this.$notify.success({
          title: "成功",
          message: res.data.msg,
          showClose: true,
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  box-sizing: border-box;
}
.wrapper {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  .header {
    height: 64px;
    width: 100%;
    background: white;
    border-bottom: 3px solid rgb(255, 103, 0);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    .header-item {
      i {
        font-size: 40px !important;
        color: rgb(255, 103, 0);
      }
      width: 1225px;
      margin: 0 auto;
      height: 64px;
      line-height: 64px;
      font-size: 28px !important;
    }
  }
  .content {
    width: 1225px;
    // height: 100px;
    height: 100%;
    margin-top: 10px;
    display: flex;
    // background: red;
    flex-wrap: wrap;
    // justify-content: center;
    .imgss {
      display: flex;
      img {
        height: 300px;
        width: 360px;
      }
      .right {
        margin-left: 30px;
        color: #b0b0b0;
        h2 {
          margin: 70px 0 15px;
          font-weight: 600;
          font-size: 36px;
        }
        p {
          margin: 0 0 20px;
          font-size: 20px;
        }
      }
    }
    .imgs-item2 {
      float: left;
      width: 234px;
      height: 280px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 10px 0;
      margin: 0 0 14.5px 13.7px;
      background-color: #fff;
      font-size: 18px;
      color: #333;
      position: relative;
      &:hover.imgs-item2 {
        box-shadow: 0 15px 30px rgb(0 0 0 / 10%);
        transform: translate3d(0, -2px, 0);
      }
    }

    .imgs-item {
      z-index: 1;
      float: left;
      width: 234px;
      height: 280px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 10px 0;
      margin: 0 0 14.5px 13.7px;
      background-color: #fff;
      // -webkit-transition: all 0.2s linear;
      transition: all 0.2s linear;
      position: relative;
      &:hover.imgs-item {
        box-shadow: 0 15px 30px rgb(0 0 0 / 10%);
        transform: translate3d(0, -2px, 0);
        .span {
          display: block;
        }
      }

      position: relative;
      .imgs-box {
        width: 160px;
        height: 160px;

        .span {
          height: 50px;
          width: 50px;
          display: none;
          text-align: center;
          font-size: 25px;
          color: rgb(171, 164, 164);
          position: absolute;
          right: 0;
          top: 0;
        }

        img {
          width: 160px;
          height: 160px;
        }
      }

      .imgs-zi {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        .h2 {
          font-size: 14px;
          color: #333;
        }
        h3 {
          margin: 5px 10px;
          height: 18px;
          font-size: 12px;
          color: #b0b0b0;
        }
        p {
          span {
            margin: 10px 10px 10px;
            font-size: 16px;
            text-align: center;
            color: #ff6700;
          }
          .del {
            margin-left: 0.5em;
            color: #b0b0b0;
            text-decoration: line-through;
          }
        }
      }
    }
  }
}
</style>
